package com.afd.ozblip.activity;

import java.util.ArrayList;
import java.util.List;

import com.afd.ozblip.adapter.NoticeListAdapter;
import com.afd.ozblip.adapter.PeopleListAdapter;
import com.afd.ozblip.entity.NoticeEntity;
import com.afd.ozblip.entity.PeopleEntity;
import com.afd.ozblip.util.CollectionUtil;
import com.afd.ozblip.util.StringUtil;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class VipActivityNoticeListActivity extends BaseActivity {

	/****************** 视图变量 **************************/
	private ListView noticeListView;
	/****************** 其它变量 **************************/
	private List<NoticeEntity> noticeList;
	private NoticeListAdapter noticeListAdapter;
	private String noticeStr;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_activity_notice_list);
		// 启动返回功能
		toBack();
		// 寻找视图
		findViews();
		// 设置监听
		setListeners();
		// 获取参数
		getBundle();
		// 获取列表数据
		requestTopListData();

	}

	/**
	 * 寻找视图
	 */
	public void findViews() {
		this.noticeListView = (ListView) findViewById(R.id.lv_vip_activity_notice_list);
	}

	/**
	 * 设置监听
	 */
	public void setListeners() {

		View.OnClickListener moreClick = new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.ll_more_layout_setting:
					Intent settingIntent = new Intent(
							VipActivityNoticeListActivity.this,
							SettingActivity.class);
					startActivity(settingIntent);
					break;

				default:
					break;
				}
			}
		};
	}

	/**
	 * 获取传递的参数
	 */
	private void getBundle() {
		Intent intent = getIntent();
		noticeStr = intent.getStringExtra("activityNoticeStr");
	}

	/**
	 * 获取评论列表数据
	 */
	private void requestTopListData() {

		if (!StringUtil.isNullOrEmpty(noticeStr)) {
			String[] noticeArr = noticeStr.split(",");
			noticeList = new ArrayList<NoticeEntity>();
			for (int i = 0, len = noticeArr.length; i < len; i++) {
				NoticeEntity notice = new NoticeEntity();
				String[] itemArr = noticeArr[i].split("@");
				notice.setNoticeContent(itemArr[0]);
				notice.setSellerName(itemArr[1]);
				noticeList.add(notice);
			}
			setPeopleListAdapter();
		}
//		NoticeEntity notice1 = new NoticeEntity();
//		notice1.setNoticeContent("公告内容1");
//		noticeList.add(notice1);
//		NoticeEntity notice2 = new NoticeEntity();
//		notice2.setNoticeContent("公告内容2");
//		noticeList.add(notice2);
//		NoticeEntity notice3 = new NoticeEntity();
//		notice3.setNoticeContent("公告内容2");
//		noticeList.add(notice3);
		
	}

	/**
	 * 调用评论列表适配器
	 */
	public void setPeopleListAdapter() {
		if (CollectionUtil.UnNullAndZero(noticeList)) {
			this.noticeListAdapter = new NoticeListAdapter(
					VipActivityNoticeListActivity.this);
			this.noticeListAdapter.addItems(noticeList);
			this.noticeListView.setAdapter(this.noticeListAdapter);
		}
	}
}